package com.ruoyi.testing.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.testing.domain.EntrustmentAgreement;
import com.ruoyi.testing.service.IEntrustmentAgreementService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 委托协议Controller
 * 
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/testing/agreement")
@Api(value="委托协议",tags = "委托协议")
public class EntrustmentAgreementController extends BaseController
{
    @Autowired
    private IEntrustmentAgreementService entrustmentAgreementService;

    /**
     * 查询委托协议列表
     */
    @GetMapping("/list")
    @ApiOperation(value="查询委托协议列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(EntrustmentAgreement entrustmentAgreement)
    {
        startPage();
        List<EntrustmentAgreement> list = entrustmentAgreementService.selectEntrustmentAgreementList(entrustmentAgreement);
        return getDataTable(list);
    }

    /**
     * 导出委托协议列表
     */
    @Log(title = "委托协议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EntrustmentAgreement entrustmentAgreement)
    {
        List<EntrustmentAgreement> list = entrustmentAgreementService.selectEntrustmentAgreementList(entrustmentAgreement);
        ExcelUtil<EntrustmentAgreement> util = new ExcelUtil<EntrustmentAgreement>(EntrustmentAgreement.class);
        util.exportExcel(response, list, "委托协议数据");
    }

    /**
     * 获取委托协议详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取委托协议详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(entrustmentAgreementService.selectEntrustmentAgreementById(id));
    }

    /**
     * 查询项目编号
     */
    @GetMapping(value = "/getAgreementNum")
    @ApiOperation(value="获取委托协议详细信息")
    public AjaxResult getAgreementNum()
    {
        return success(entrustmentAgreementService.selectEntrustmentAgreementNum());
    }

    /**
     * 根据项目类别和年代号获取项目编号
     */
    @GetMapping("/getAgreementNum/{itemType}/{itemYear}")
    @ApiOperation(value="根据项目类别和年代号获取项目编号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "itemType", value = "类别", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "itemYear", value = "年份", required = true, dataType = "String"),
    })
    public AjaxResult getAgreementNum(@PathVariable("itemType") String itemType, @PathVariable("itemYear") String itemYear){
        return AjaxResult.success("操作成功", entrustmentAgreementService.selectAgreementNumMax(itemType, itemYear));
    }

    /**
     * 新增委托协议
     */
    @Log(title = "委托协议", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增委托协议")
    public AjaxResult add(@ApiParam(name="委托协议对象",value="传入json格式",required=true) @RequestBody EntrustmentAgreement entrustmentAgreement)
    {
        return toAjax(entrustmentAgreementService.insertEntrustmentAgreement(entrustmentAgreement));
    }



    /**
     * 修改委托协议
     */
    @Log(title = "委托协议", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改委托协议")
    public AjaxResult edit(@ApiParam(name="委托协议对象",value="传入json格式",required=true)@RequestBody EntrustmentAgreement entrustmentAgreement)
    {
        return toAjax(entrustmentAgreementService.updateEntrustmentAgreement(entrustmentAgreement));
    }

    /**
     * 删除委托协议
     */
    @Log(title = "委托协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除委托协议")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(entrustmentAgreementService.deleteEntrustmentAgreementByIds(ids));
    }
}
